package com.yzt.minemodule.adapter;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.yzt.zhuju.network.entity.mine.GiftListBean;
import com.yzt.minemodule.R;

/**
 * author : bob
 * date   : 2022/12/7
 * desc   : 个人详情页的礼物适配器
 */
public class PersonalGiftNewAdapter extends BaseQuickAdapter<GiftListBean.GiftListDTO, BaseViewHolder> implements LoadMoreModule {

    public PersonalGiftNewAdapter() {
        super(R.layout.item_personal_gift);
    }

    @Override
    protected void convert(BaseViewHolder holder, GiftListBean.GiftListDTO item) {

//        holder.setText(R.id.gift_name, item.getName());
//
//        ImageView iconIv = holder.getView(R.id.gift_icon);
//        if (TextUtils.isEmpty(item.getIcon())) {
//            iconIv.setImageResource(R.mipmap.icon_personal_bottom_gift_more);
//        } else {
//            if (item.isHave()) {
//                holder.setText(R.id.gift_content_tv, "x" + StringUtils.getNumK(item.getNum(), StringUtils.FORMAT_DECIMAL_POINT_1));
//                holder.setTextColor(R.id.gift_name, ContextCompat.getColor(getContext(), R.color.color_262628));
//                ImageLoadUtil.load(getContext(), item.getIcon(), iconIv, R.mipmap.icon_gift_default_white);
//            } else {
//                holder.setText(R.id.gift_content_tv, getContext().getString(R.string.un_light));
//                holder.setTextColor(R.id.gift_name, ContextCompat.getColor(getContext(), R.color.color_6d7278));
//                ImageLoadUtil.load4Drawable(getContext(), item.getIcon(), new ImageLoadUtil.ImageRequestListener() {
//                    @Override
//                    public void onResourceReady(@NonNull @NotNull Drawable resource) {
//                        Bitmap bitmap = ((BitmapDrawable) resource).getBitmap();
//                        iconIv.setImageBitmap(grayScale(bitmap));
//                    }
//
//                    @Override
//                    public void onError() {
//                        iconIv.setImageResource(R.mipmap.icon_gift_default_white);
//                    }
//                });
//            }
//        }
    }

    /**
     * 图片灰度处理
     */
    public static Bitmap grayScale(Bitmap bitmap) {
        int width, height;
        height = bitmap.getHeight();
        width = bitmap.getWidth();
        Bitmap bmpGray = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(bmpGray);
        Paint paint = new Paint();
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
        paint.setColorFilter(f);
        c.drawBitmap(bitmap, 0, 0, paint);
        return bmpGray;
    }
}

